<template>
  <div class="realNameVerification-wrap">
    <div class="title"><span>{{ user_info.mobile }} </span> 成功认证即可参与购买</div>
    <div class="poster"><span>* </span> 请确认注册手机号与实名信息匹配</div>
    <van-form @submit="onSubmit">
      <!-- 可以使用 CellGroup 作为容器 -->
      <van-cell-group inset>
        <van-field v-model="formData.userName" placeholder="请输入真实姓名" />
        <van-field v-model="formData.idCard" placeholder="请输入身份证号码" />
      </van-cell-group>
      <van-checkbox v-model="formData.checked" checked-color="#37dc6d">
        <div class="isAggressDiv">
          我已阅读并同意
          <span @click="openAgreement(1)">《用户协议》</span>
          <span @click="openAgreement(2)">《隐私政策》</span>
        </div>
      </van-checkbox>
      <van-button type="primary" class="block_gradual" :loading="formData.loading" native-type="submit">开始认证
      </van-button>
    </van-form>
  </div>
  <privacy-policy :agreementData="agreementData" />
</template>
<script>
import { defineComponent, reactive, computed } from 'vue'
import { Toast } from "vant";
import { useStore } from "vuex";
import { useRouter } from 'vue-router'
import { editIdCard } from "@/api/user";
import privacyPolicy from '@/components/privacyPolicy'
import { formatPhoneNumber } from "@/utils/phone";
export default defineComponent({
  components: {
    privacyPolicy
  },
  setup() {
    const store = useStore();
    const router = useRouter()
    const user_info = computed(() => {
      return store.getters.user_info
    })
    const formData = reactive({
      idCard: "",
      userName: "",
      checked: false,
      loading: false
    })
    const agreementData = reactive({
      status: false,
      type: 1
    })
    const openAgreement = (type) => {
      agreementData.status = true
      agreementData.type = type
    }
    const onSubmit = async () => {
      formData.loading = true
      console.log(formData.idCard)
      const paramrs = {
        idCard: formData.idCard,
        username: formData.userName
      }
      if (!formData.checked) {
        Toast("请勾选我已阅读并同意《用户协议》《隐私政策》");
        return
      }
      if (!formData.userName || !formData.idCard) {
        Toast("请输入完整信息");
        return
      }

      const res = await editIdCard(paramrs)

      if (res.data.success) {
        Toast("认证成功");
        router.back()
        formData.loading = false

      }
      // editIdCard(paramrs).then(async res => {
      //   if (res.data.success) {
      //     Toast("认证成功");
      //     await store.dispatch('user/getUserAll')
      //     router.back()
      //   }
      // })
      formData.loading = false
    }
    return {
      formData,
      onSubmit,
      user_info,
      formatPhoneNumber,
      openAgreement, agreementData
    }
  },

})
</script>
<style lang="less" scoped>
.realNameVerification-wrap {
  .title {
    font-size: 36px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #ffffff;

    span {
      font-size: 36px;
      font-family: Source Han Sans CN;
      font-weight: 400;
      color: #ffffff;
      line-height: 95px;
      background: linear-gradient(-90deg, #37dc6d 0%, #34d1f9 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }
  }

  padding: 40px 33px;

  &:deep(.van-field__control) {
    color: #fff;
  }

  &:deep(.van-cell-group) {
    margin: 0px 0px;
    background: transparent;
  }

  &:deep(.van-field) {
    height: 100px;
    background: #282a2c;
    border: 1px solid #ffffff;
    border-radius: 18px;
  }

  .poster {
    font-size: 24px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #ffffff;
    opacity: 0.8;

    span {
      color: #fa0000;
    }
  }

  .van-form {
    margin-top: 60px;

    .van-row {
      font-size: 28px;
      font-weight: 400;
      color: #333;
      line-height: 48px;
    }

    .van-checkbox {
      margin-top: 60px;

      &:deep(.van-checkbox__icon) {
        width: 26px;
        height: 26px;
        font-size: 26px;
      }

      .isAggressDiv {
        font-size: 28px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #ffffff;
        line-height: 48px;
        opacity: 0.6;

        span {
          font-size: 28px;
          font-family: Source Han Sans CN;
          font-weight: 400;
          color: #ffffff;
          line-height: 48px;

          background: linear-gradient(-90deg, #37dc6d 0%, #34d1f9 100%);
          -webkit-background-clip: text;
          -webkit-text-fill-color: transparent;
        }
      }
    }

    .van-button {
      margin-top: 20px;
    }
  }
}
</style>